package com.cmf.myproject.controller.boss.task;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cmf.myproject.dal.mybatis.enums.TaskStatusEnum;
import com.cmf.myproject.dal.mybatis.filters.TaskQueryFilter;
import com.cmf.myproject.dal.mybatis.mymodel.TaskProject;
import com.cmf.myproject.service.project.ProjectService;
import com.cmf.myproject.service.security.dto.LoginUserInfo;
import com.cmf.myproject.service.task.TaskService;
import com.system.core.controller.ControllerBase;
import com.system.core.view.layui.table.TableViewRspDto;

@Controller
@RequestMapping("/user/task")
public class UserTaskController extends ControllerBase {
	
	@Autowired
	private TaskService taskService;
	@Autowired
	private ProjectService projectService;

	@RequiresPermissions("task_topage")
	@RequestMapping(value = "/task_topage",method = RequestMethod.GET)
	public String toPage() {
		getModelMap().put("statusEnums", TaskStatusEnum.getAllEnum());
		getModelMap().put("projectAllList", projectService.projectAllEnableList());
		return "/boss/mytask/task-list";
	}
	
	@RequestMapping(value = "query_list",method = RequestMethod.POST)
	@ResponseBody
	public TableViewRspDto<TaskProject> taskQueryList(TaskQueryFilter filter) {
		Subject subject = SecurityUtils.getSubject();
		LoginUserInfo userinfo = (LoginUserInfo)subject.getPrincipal();
		filter.setUserId(Long.parseLong(userinfo.getId()));
		TableViewRspDto<TaskProject> rsp = taskService.taskList(filter);
		return rsp;
	}
}
